﻿using Command.CommunityToolkit.Attributes;

namespace Command.CommunityToolkit.Commands.Impl;

[Command(("log"))]
public class LogCommand : CommandBase
{
    public LogCommand(object args, IQualityControl qualityControl) : base(args, qualityControl)
    {
    }
    public override string Summary() => "打印当天日志内容";

    public override string Description() =>
        @"输出当日执行日志信息";

    public override string[] GetLicenses()
    {
        return new string[]{};
    }

    public override bool Excute()
    {
        var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
            $@"Logs\Info\{DateTime.Now.ToString("yyyy-MM-dd")}.log");
        if (File.Exists(path))
        {
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            int fsLen = (int)fs.Length;
            byte[] heByte = new byte[fsLen];
            _ = fs.Read(heByte, 0, heByte.Length);
            var log = System.Text.Encoding.GetEncoding("UTF-8").GetString(heByte);
            ConsoleResult(log);
            return true;
        }
        Console.WriteLine($"没有找到日志文件{path}");
        return false;
    }


}